package cn.wh.xwm.controller.interceptor;

import java.util.Map;  

import cn.wh.xwm.common.util.Constant;
import cn.wh.xwm.controller.action.LoginAction;
import cn.wh.xwm.hibernate.dao.Userinfo;

import com.opensymphony.xwork2.Action;  
import com.opensymphony.xwork2.ActionContext;  
import com.opensymphony.xwork2.ActionInvocation;  
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class SessionIterceptor extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation actionInvocation) throws Exception {
		ActionContext ctx = ActionContext.getContext();  
        Map session = ctx.getSession();  
        Action action = (Action) actionInvocation.getAction();  
        if (action instanceof LoginAction) {  
            return actionInvocation.invoke();  
        }  
        Userinfo userinfo = (Userinfo) session.get(Constant.USER_SESSION);  
        if (userinfo == null) {  
            return Constant.RELOGIN;  
        } else {  
            return actionInvocation.invoke();  
        }  
	}

}
